package com.lhq.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class RedisController {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Async
    @GetMapping("/redis/add")
    public String put(String key, String value) {
        redisTemplate.opsForValue().set(key, value,1, TimeUnit.DAYS);
        return "OK";
    }

    @GetMapping("/redis/get")
    public String get(String key) {
        String value = redisTemplate.opsForValue().get(key);
        return value;
    }
}
